package org.ling.xuan.action;

import cn.hutool.core.util.StrUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
import org.ling.xuan.condition.LxCondition;
import org.ling.xuan.dao.ProjectDao;
import org.ling.xuan.util.LoggerUtil;
import org.ling.xuan.util.LxOptional;

/**
 * 删除项目
 *
 * @author liting50684
 * @date 2023/08/01
 */
public class LxRemoveProjectAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        String basePath = LxOptional.of(e, c -> c.getProject().getBasePath()).orElse("");
        if (StrUtil.isNotBlank(basePath)) {
            ProjectDao.delete(basePath);
            LoggerUtil.log(e.getProject(), "项目移除成功");
        } else {
            LoggerUtil.log(e.getProject(), "无效的删除操作");
        }
    }

    @Override
    public void update(AnActionEvent e) {
        boolean enable = LxCondition.getInstance().projectRemoveCondition(e);
        e.getPresentation().setEnabledAndVisible(enable);
    }
    
}
